package cn.jsj.dispose;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
 * 修改用户密码处理类
 * @author LI
 *
 */
 public class ModifyPersonalPwd extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		//调试信息
		 cn.jsj.utils.SysLogger.PrintInfo("修改用户密码！！！");

		 //获得参数
		 String oldPwd=request.getParameter("old_pwd");
		 String newPwd=request.getParameter("new_pwd");
		 String confirmPwd=request.getParameter("confirm_new_pwd");
		 //用户id和角色编号
		 int userId=Integer.parseInt(request.getParameter("userId"));
		 int role=Integer.parseInt(request.getParameter("role"));

		 //输出对象
		 java.io.PrintWriter out=response.getWriter();
		 //判断两次输入的结果是否相同
		 if(!newPwd.equalsIgnoreCase(confirmPwd))
		 {
			 out.println("{message:'两次输入密码不同！'}");
			 out.flush();
			 return;
		 }

		 // 调试信息
		 cn.jsj.utils.SysLogger.PrintInfo("oldPwd---->"+oldPwd+"    "+userId+"    "+role);

		 //修改结果 1.成功 0 失败
		 int modifyResult;
		 //role:1. 律师 2.实习律师 3.行政人员 4.律师助理
		 if(role==1){
			 cn.jsj.dao.TblLawyerDAO tld=new cn.jsj.dao.TblLawyerDAO();
			modifyResult= tld.modifyPassword(oldPwd, newPwd, userId);

			//调试信息
			cn.jsj.utils.SysLogger.PrintInfo("修改结果-------->"+modifyResult);

			//判断修改结果
			if(modifyResult==1){
				out.println("{message:'修改成功'}");
				out.flush();
				 return;
			}
			else{
				out.println("{message:'修改失败！'}");
				out.flush();
				 return;
			}
		 }

		 //如果为行政人员
		 if(role==3){
			 cn.jsj.dao.TblAdminPersonnelDAO tapd=new cn.jsj.dao.TblAdminPersonnelDAO();
			 modifyResult=tapd.modifyPassword(oldPwd, newPwd, userId);
			//调试信息
				cn.jsj.utils.SysLogger.PrintInfo("修改结果3-------->"+modifyResult);

			//判断修改结果
				if(modifyResult==1){
					out.println("{message:'修改成功'}");
					out.flush();
					 return;
				}
				else{
					out.println("{message:'修改失败！'}");
					out.flush();
					 return;
				}
		 }

	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request,response);
	}
}